<?php

if (!defined('FRAMEWORKS_RB_FUNCTIONS_TOKEN')):
define('FRAMEWORKS_RB_FUNCTIONS_TOKEN', true);


// CreateToken
function rb_token_create($token_name='XOOPS')
{
	if( substr( XOOPS_VERSION , 6 , 3 ) > 2.0 ) {
		// XOOPS 2.1/2.2
		$token = $GLOBALS['xoopsSecurity']->createToken();
	} else {
		// XOOPS 2.0.x
		$token_handler = new XoopsMultiTokenHandler();
		$ticket = &$token_handler->create($token_name);
		$token = $ticket->fetch();
	}
	return $token;
}

function rb_token_get($token_name='XOOPS')
{
	if( substr( XOOPS_VERSION , 6 , 3 ) > 2.0 ) {
		// XOOPS 2.1/2.2
		$token = $GLOBALS['xoopsSecurity']->getTokenHTML();
	} else {
		// XOOPS 2.0.x
		$token_handler = new XoopsMultiTokenHandler();
		$ticket = &$token_handler->create($token_name);
		$token = $ticket->getHtml();
	}
	return $token;
}

// Token 認證
function rb_token_check($token_name='XOOPS')
{
	$token = false;
	if( substr( XOOPS_VERSION , 6 , 3 ) > 2.0 ) {
		// XOOPS 2.1/2.2
		if ($GLOBALS['xoopsSecurity']->check(true, $_REQUEST['XOOPS_TOKEN_REQUEST'])) {
			$token = true;
		}
	} else {
		// XOOPS 2.0.x
		$token_handler = new XoopsMultiTokenHandler();
		if($token_handler->autoValidate($token_name)) {
			$token = true;
		}
	}
	return $token;
}

endif;
?>